export default function (config) {
    let ajax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject();
    if (config.method === "GET") {
        config.url += '?';
        for (let key in config.data) {
            config.url += `${key}=${config.data[key]}&`
        }
        ajax.open("GET", config.url, true);
        console.log(config.url);
        ajax.send()
    }

    if (config.method === "POSTB") {
        ajax.open("POST", config.url, true);
        let formData = new FormData();
        for (const key in config.data) {
            formData.append(key, config.data[key]);
        }
        ajax.send(formData)
    }

    if (config.method === "POSTA") {
        ajax.open("POST", config.url, true);
        ajax.setRequestHeader("Content-Type","application/json")
        ajax.send(JSON.stringify(config.data))
    }

    return new Promise((resolve, reject) => {
        ajax.onreadystatechange = function () {
            if (ajax.readyState === 4 && ajax.status === 200) {
                resolve(ajax.response)
            }
        }
    })
}